package com.luoc.base.channel;


import io.netty.channel.Channel;
import io.netty.channel.group.DefaultChannelGroup;
import io.netty.util.concurrent.GlobalEventExecutor;

import java.util.concurrent.ConcurrentHashMap;

/**
 * @Author: luoc
 * @Date: 2019/7/16 9:21
 * 绑定公会,退出公会 公会存储类型
 */
public class GuildChannelRel {

    public static ConcurrentHashMap<String, DefaultChannelGroup> manager = new ConcurrentHashMap<>();

    public static ConcurrentHashMap<String, String> userGuild = new ConcurrentHashMap<>();

    public static void put(String sendId, String mid, Channel channel) {

        DefaultChannelGroup defaultChannelGroup = null;
        if (manager.get(mid) == null) {
            defaultChannelGroup = new DefaultChannelGroup(mid, GlobalEventExecutor.INSTANCE);
        } else {
            defaultChannelGroup = manager.get(mid);
        }
        defaultChannelGroup.add(channel);
        manager.put(mid, defaultChannelGroup);
        userGuild.put(sendId, mid);
         /*if (channels == null){
                channels = new ArrayList<>();
            }*/
         /*   channels.add(channel);
            manager.put(mid,channels);*/
    }

    /**
     * todo 退出公会时需要删除chanel(重新发送一次请求,退出公会)
     *
     * @param channel
     */
    public static void del(Channel channel) {

    }

    public static DefaultChannelGroup get(String mid) {
        return manager.get(mid);
    }


   /* public static void output() {
        for (HashMap.Entry<String, List<Channel>> entry : manager.entrySet()) {
            System.out.println("UserId: " + entry.getKey()
                    + ", ChannelId: " + JSON.toJSON(entry.getValue()));
        }
    }*/

}
